const express = require('express');
const app = express();

// Log all requests
app.use((req, res, next) => {
  console.log(`[${new Date().toISOString()}] Request received: ${req.method} ${req.url}`);
  next();
});

// Wildcard route using * - this captures everything
app.get('/test/*', (req, res) => {
  // Log the complete URL and path
  console.log('Wildcard route triggered');
  console.log('Original URL:', req.originalUrl);
  console.log('Base URL:', req.baseUrl);
  console.log('Path:', req.path);
  
  // Extract the part after /test/
  const wildcardPath = req.originalUrl.substring('/test/'.length);
  console.log('Extracted wildcard path:', wildcardPath);
  
  // Send response with the extracted information
  res.json({
    message: 'Wildcard route test successful',
    originalUrl: req.originalUrl,
    wildcardPath: wildcardPath,
    timestamp: new Date().toISOString()
  });
});

// Basic route just for testing
app.get('/', (req, res) => {
  res.send('Server is running. Try accessing /test/anything/you/want to test the wildcard route.');
});

// Start the server
const PORT = 3000;
app.listen(PORT, () => {
  console.log(`Test server running on http://localhost:${PORT}`);
  console.log(`Try accessing http://localhost:${PORT}/test/anything/you/want to test the wildcard route`);
});